package org.database.generator.code.utils;

import java.io.IOException;
import java.util.Properties;

/**
 * @author liangsu
 * @version v1.0
 * @Description
 * @Date 2019/8/27 10:34
 * @since
 */
public class Configuration {

    private static Properties props;

    static {
        props = new Properties();
        try {
            props.load(Configuration.class.getClassLoader().getResourceAsStream("application.properties"));
        } catch (IOException e) {
            throw new RuntimeException("没读到配置文件application.properties");
        }
    }

    public static String get(String key){
        return props.getProperty(key);
    }

    public static String getDBName(){
//        jdbc:mysql://192.168.10.25:18020/helmet_web
        String driver = get("spring.datasource.url");
        int start = driver.lastIndexOf("/");
        int end = driver.indexOf("?");

        String dbName = null;
        if(start > -1){
            dbName = driver.substring(start + 1);
            if(end > -1){
                dbName.substring(0, end - 1);
            }
        }
        return dbName;
    }

}
